# -*- coding: utf-8 -*-
"""
Web framework/Tornado Router/test02.py
"""
import tornado.web
import asyncio
from tornado.routing import Router, RuleRouter, PathMatches, Rule
from tornado.httpserver import HTTPServer
from tornado.httputil import HTTPServerRequest


class UserHandler(tornado.web.RequestHandler):
    def get(self):
        r_message = "Welcome to UserHandler Get Method."
        self.finish(r_message)


class PhotoHandler(tornado.web.RequestHandler):
    def get(self):
        r_message = "Welcome to PhotoHandler Get Method."
        self.finish(r_message)


app_v1 = tornado.web.Application([
    (r'/v1/user/', UserHandler)
])

app_v2 = tornado.web.Application([
    (r'/v2/photo/', PhotoHandler)
])


async def main():
    router = RuleRouter([
        Rule(PathMatches('/v1.*'), app_v1),
        Rule(PathMatches('/v2.*'), app_v2)
    ])
    server = HTTPServer(router)
    server.listen(8888)
    await asyncio.Event().wait()


if __name__ == '__main__':
    asyncio.run(main())
